import axios from 'axios'
import nProgress from 'nprogress'
import store from '@/store'
import 'nprogress/nprogress.css'


const requests = axios.create({
    baseURL: '/api',
    timeout: 5000
})

requests.interceptors.request.use((config) => {
    nProgress.start()
    config.headers.userTempId=store.state.detail.userID
    config.headers.token=store.state.user.token
    return config
})

requests.interceptors.response.use((res) => {
    nProgress.done()
    return res.data
}, function (error) {
    // 超出 2xx 范围的状态码都会触发该函数。
    // 对响应错误做点什么
    return Promise.reject(error);
})

export default requests